with v8.Class_String;
with v8.Class_Heap_Graph_Node;
with v8.Class_Output_Stream;
package v8.Class_Heap_Snapshot is
   type Heap_Snapshot (<>) is tagged limited private;
   type Pointer is access all Heap_Snapshot;
   type Reanonly_Pointer is access constant Heap_Snapshot;
   -- record the state of the JS heap at some moment.

   function Get_Type (this : Heap_Snapshot) return Heap_Snapshot_Type.Enum;
   -- Returns heap snapshot type.

   function Get_Uid (this : Heap_Snapshot) return unsigned;
   -- Returns heap snapshot UID (assigned by the profiler.)

   function Get_Title (this : Heap_Snapshot) return v8.Class_String.Pointer;
   -- Returns heap snapshot title.(return Handle<String>)

   function Get_Root
     (this : Heap_Snapshot
     ) return v8.Class_Heap_Graph_Node.Readonly_Pointer;
   -- Returns the root node of the heap graph.

   function Get_Node_By_Id
     (this : Heap_Snapshot;
      id   : uint64_t
     ) return v8.Class_Heap_Graph_Node.Readonly_Pointer;
   -- Returns a node by its id.

   function Get_Nodes_Count (this : Heap_Snapshot) return int;
   -- Returns total nodes count in the snapshot.

   function Get_Node
     (this  : Heap_Snapshot;
      index : int
     ) return v8.Class_Heap_Graph_Node.Readonly_Pointer;
   -- Returns a node by index.

   procedure Delete (this : in out Heap_Snapshot);
   -- Deletes the snapshot and removes it from HeapProfiler's list.
   -- All pointers to nodes, edges and paths previously returned become
   -- invalid.

   procedure Serialize
     (this   : Heap_Snapshot;
      stream : access v8.Class_Output_Stream.Output_Stream'Class;
      format : Heap_Snapshot_Serialization_Format.Enum);
   -- Prepare a serialized representation of the snapshot. The result
   -- is written into the stream provided in chunks of specified size.
   -- The total length of the serialized snapshot is unknown in
   -- advance, it can be roughly equal to JS heap size (that means,
   -- it can be really big - tens of megabytes).
   --
   -- For the JSON format, heap contents are represented as an object
   -- with the following structure:
   --
   --  {
   --    snapshot: {title: "...", uid: nnn},
   --    nodes: [
   --      meta-info (JSON string),
   --      nodes themselves
   --    ],
   --    strings: [strings]
   --  }
   --
   -- Outgoing node links are stored after each node. Nodes reference strings
   -- and other nodes by their indexes in corresponding arrays.


private
   type Heap_Snapshot is tagged limited null record;

   pragma Import (CPP, Get_Type, "_ZNK2v812HeapSnapshot7GetTypeEv");
   pragma Import (CPP, Get_Uid, "_ZNK2v812HeapSnapshot6GetUidEv");
   pragma Import (CPP, Get_Title, "_ZNK2v812HeapSnapshot8GetTitleEv");
   pragma Import (CPP, Get_Root, "_ZNK2v812HeapSnapshot7GetRootEv");
   pragma Import (CPP, Get_Node_By_Id, "_ZNK2v812HeapSnapshot11GetNodeByIdEy");
   pragma Import (CPP, Get_Nodes_Count, "_ZNK2v812HeapSnapshot13GetNodesCountEv");
   pragma Import (CPP, Get_Node, "_ZNK2v812HeapSnapshot7GetNodeEi");
   pragma Import (CPP, Delete, "_ZN2v812HeapSnapshot6DeleteEv");
   pragma Import (CPP, Serialize, "_ZNK2v812HeapSnapshot9SerializeEPNS_12OutputStreamENS0_19SerializationFormatE");
end v8.Class_Heap_Snapshot;
